﻿@{
    var cat = (Guline.Web.XjsGame.Models.ICat)ViewBag.Cat;
    ViewBag.Title = cat.Name;
    Layout = "~/Views/Shared/_xjsLayout.cshtml";
    int currentPage = (int)ViewBag.newsPage;
}
<script>
    $(document).ready(function () {
        $(".notifymenu li a").removeClass("cactive");
        $(".notifymenu li a[data-catid='@(cat.ID)']").addClass("cactive");
        $(window).scroll(function () {
            if (document.documentElement.clientHeight +
                  $(document).scrollTop() >= document.body.offsetHeight) {
                // Display alert or whatever you want to do when you're 
                //   at the bottom of the page. 
                if ($("#btnreadmore").length > 0) {
                    $("#btnreadmore").click();
                }
            }
        });
        $("#btnreadmore").click(function () {
            var newspage = parseInt($(this).attr("data-currentpage"));
            var button = $(this);
            if (button.attr("disabled") == "disabled") {
                button.remove();
                return false;
            }
            button.find(".hook").html("<img src='@Url.Content("~/Content/images/utils/loading.gif")'/>");
            button.attr("disabled", "disabled");
            $.ajax({
                type: "get",
                url: "@Url.Action("getNewsTypePage")/?newsPage=" + newspage + "&CatID=@(cat.ID)",
                datatype: "json",
                success: function (data) {

                    if (data.ismax) {
                        button.attr("disabled", "disabled");
                        button.remove();
                    }
                    else {
                        var html_next_p = "";
                        $(data.list).each(function (index, news) {
                            var parsedDate = new Date(parseInt(news.date_added.substr(6)));
                            var jsDate = new Date(parsedDate); //Date object


                            if (news.image == "") {
                                html_next_p += "<div class='post'>";

                                html_next_p += "<div class='user_detail'>";
                                html_next_p += "<a class='name_user' href='@(@Request.Url.GetLeftPart(UriPartial.Authority))/goto/i" + news.id + "'>" + news.name + "</a>";

                                html_next_p += "<div class='clr'></div>";
                                html_next_p += "</div>";
                                html_next_p += "<div class='clr'></div>";
                                html_next_p += "<div class='time_line'>";
                                html_next_p += "<a class='time'>" + jsDate.getDate() + "-" + jsDate.getMonth() + "-" + jsDate.getFullYear() + " " + jsDate.getHours() + ":" + jsDate.getMinutes() + "</a>";
                                html_next_p += "<span class='point'>· </span>";
                                html_next_p += "<a class='earth'></a>";
                                html_next_p += "<div class='clr'></div>";
                                html_next_p += "</div>";
                                html_next_p += "<a class='option_center'></a>";
                                html_next_p += "<div class='post_status'>";
                                html_next_p += news.detail_short;
                                html_next_p += "<div class='clr'></div>";
                                html_next_p += "</div>";
                                html_next_p += "<div class='clr'></div>"
                                html_next_p += "</div>";
                                html_next_p += "<div class='clr'></div>"
                            }
                            else {
                                html_next_p += "<div class='commercial'>";


                                html_next_p += "<a class='title_product' href='@(@Request.Url.GetLeftPart(UriPartial.Authority))/goto/i" + news.id + "'>" + news.name + "</a>";

                                html_next_p += "<div class='clr'></div>";

                                html_next_p += " <div class='commercial_left'>";
                                html_next_p += "<a href='@(@Request.Url.GetLeftPart(UriPartial.Authority))/goto/i" + news.id + "'><img class='pic_product' src='" + news.image + "' width='106' height='95' /></a>";
                                html_next_p += "<div class='clr'></div>";
                                html_next_p += "<div class='time_line'>";
                                html_next_p += "<a class='time'>" + jsDate.getDate() + "-" + jsDate.getMonth() + "-" + jsDate.getFullYear() + " " + jsDate.getHours() + ":" + jsDate.getMinutes() + "</a>";

                                html_next_p += " <div class='clr'></div>";
                                html_next_p += "</div>";
                                html_next_p += "<div class='clr'></div>";
                                html_next_p += "</div>";
                                html_next_p += " <div class='commercial_right'>";
                                html_next_p += " <div class='post_status'>";
                                html_next_p += news.detail_short;
                                html_next_p += "<div class='clr'></div>";
                                html_next_p += "</div>";
                                html_next_p += "</div>";
                                html_next_p += " <a class='option_center'></a>";
                                html_next_p += " <div class='clr'></div>";
                                html_next_p += "<div class='clr'></div>"
                                html_next_p += "</div>";
                                html_next_p += "<div class='clr'></div>"
                            }
                        });

                        button.removeAttr("disabled");
                        $("#newsZone").append(html_next_p);
                        if (history && history.pushState) {
                            history.pushState(null, null, '/@(Guline.Web.XjsGame.Infrastructure.Utils.UrlRewriteString(cat.Name))/page-' + newspage + "-ic@(cat.ID)");
                        }
                        button.attr("data-currentpage", newspage + 1);

                    }
                    button.find(".hook").html('');

                }

            });
            return false;
        });
    });
</script>
<div class="box-news">
    <div class="brackcrum">
        <a class="" href="@Url.Action("Index", "Home")">Trang chủ  &raquo;</a> @cat.Name
    </div>
    <div class="clr"></div>
    <div class="user_detail" style="margin-bottom: 5px; margin-top: 5px;">
        <h2>@cat.Name</h2>
        <div class="clr"></div>
    </div>
    <div class="clr"></div>
    <div class="box-news-content">
        <div id="newsZone">
            @foreach (var m in Model)
            {
                if (m.image != "")
                {
              
                <div class="commercial">
                    <a href="@Url.Action("Detail", "Content", new { ID = m.id, Title = Guline.Web.XjsGame.Infrastructure.Utils.UrlRewriteString(m.name) })" class="title_product">@m.name</a>
                    <div class="clr"></div>
                    <div class="commercial_left">
                       <a href="@Url.Action("Detail", "Content", new { ID = m.id,Title=Guline.Web.XjsGame.Infrastructure.Utils.UrlRewriteString(m.name) })"><img class="pic_product" src="@Url.Content(m.image)" width="106" height="95" /></a>
                        <div class="clr"></div>
                        <div class="time_line">
                            <a class="time">@m.date_added.ToString("dd/M/yyyy hh:mm")</a>

                            <div class="clr"></div>
                        </div>
                        <div class="clr"></div>
                    </div>
                    <div class="commercial_right">
                        <div class="post_status">
                            @Html.Raw(m.detail_short)
                            <div class="clr"></div>
                        </div>
                    </div>
                    <a class="option_center"></a>
                    <div class="clr"></div>
                </div>
                <div class="clr"></div>
                }
                else
                {
                <div class="post">

                    <div class="user_detail">
                        <a class="name_user" href="@Url.Action("Detail", "Content", new { ID = m.id, Title = Guline.Web.XjsGame.Infrastructure.Utils.UrlRewriteString(m.name) })">@m.name</a>

                        <div class="clr"></div>
                    </div>
                    <div class="clr"></div>
                    <div class="time_line">
                        <a class="time">@m.date_added.ToString("dd/M/yyyy hh:mm")</a>
                        <span class="point">· </span>
                        <a class="earth"></a>
                        <div class="clr"></div>
                    </div>
                    <a class="option_center"></a>
                    <div class="post_status">
                        @Html.Raw(m.detail_short)
                        <div class="clr"></div>
                    </div>
                    <div class="clr"></div>
                </div> 
                <div class="clr"></div>
                }
            }
        </div>
        <!--  -->
        @if (currentPage > 1)
        {
            <a href="#" id="btnreadmore" data-currentpage="@currentPage" style="padding: 5px 10px; text-align: center; background: #fff;color:#4c66a4; border: 1px solid #dfe0e4; display: block"><span class="hook"></span>Xem thêm &raquo;</a>
        }
        <div class="clr"></div>
    </div>
</div>
